package ru.mera.aaclog.db;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * @version 1.0 3/03/2013
 * @author anavdeev
 */
@Entity
@Table(name="messages_raw")
@NamedQueries( {
    @NamedQuery(name = MessageBody.GET_BY_MSG, 
                query = "SELECT mb FROM MessageBody AS mb WHERE mb.message = ?1"),
    @NamedQuery(name = MessageBody.GET_BY_LOG, 
                query = "SELECT mb FROM LogHeader l, MessageHeader m, MessageBody mb WHERE l.id = ?1 AND m.log = l.id AND mb.message=m.id ORDER BY mb.id")
} )
public class MessageBody implements Serializable {
    
    public static final String GET_BY_MSG = "getMsgBody";
    public static final String GET_BY_LOG = "getRawByLog";

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "mraw_id")
    private int id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "mraw_mess", nullable = false)
    private MessageHeader message;
    
    @Column(name = "mraw_value", length=32000)
    private String value;

    public MessageBody() {
        // Serializable ctor
    }

    public MessageBody(Integer id) {
        this.id = id;
    }
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public MessageHeader getMessage() {
        return message;
    }

    public void setMessage(MessageHeader message) {
        this.message = message;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    
}
